import Vue from 'vue'
import Vuex from 'vuex'
import mutations from './mutations'
import actions from './action'
import Cookies from 'js-cookie';

Vue.use(Vuex)

const state = {
    token: Cookies.get(process.env.COOKIE_NAME + '_token'),
    companyName: Cookies.get(process.env.COOKIE_NAME + '_companyName') || undefined,
    headUrl: undefined,
    mobile: undefined,
    userId: undefined,
    userName: undefined,
    linkName: Cookies.get(process.env.COOKIE_NAME + '_linkName') || undefined,
    privilegeTree: undefined, // 导航加菜单树状图
    power: undefined, // 当前菜单下的权限
    currentPage: '', // 当前导航的位置
    menuIndex: {}, // 当前导航下的菜单树状图
    defaultAsideActive: undefined, // 默认当前侧边栏打开的导航
    asideActive: undefined, // 当前侧边栏选中
    path: [], // 当前路径导航
    sub: null, // 是否叶子 true => 叶子  false => 非叶子
    asideIsClick: false, // 侧边栏是否点击 还是回退触发
    isReLoadData: false, // 是否需要重新加载页面内的数据
    applicationState: 3, // 0待审核  1已审核  2驳回  3未提交
    isEntry: false, //是否入住
    merchantId: Cookies.get(process.env.COOKIE_NAME + '_merchantId') || undefined, // 商户id
    userInfo: Cookies.get(process.env.COOKIE_NAME + '_userInfo') || undefined,// 商户名
    isShop: Cookies.get(process.env.COOKIE_NAME + '_isShop'), //是否门店 0是
    soUrce: Cookies.get(process.env.COOKIE_NAME + '_soUrce') || undefined,//'来源 0：运营平台创建；1：商户平台申请入住；2：商户平台门店管理；3：商户平台供应商管理；4：商户平台客户管理  5:商米平台'
    isOwnAuth: Cookies.get(process.env.COOKIE_NAME + '_isOwnAuth') || undefined, //自主管理
    businessScope: Cookies.get(process.env.COOKIE_NAME + '_businessScope') || undefined, //门店经营范围  0-商品售卖 1-服务预约 2-小儿游泳
    shopType: Cookies.get(process.env.COOKIE_NAME + '_shopType') || undefined, //门店类型
}
const getters = {
    token: state => state.token,
    merchantId: state => state.merchantId,
    companyName: state => state.companyName,
    userInfo: state => state.userInfo,
    linkName: state => state.linkName,
    isShop: state => state.isShop,
    soUrce: state => state.soUrce,
    isOwnAuth: state => state.isOwnAuth,
    businessScope: state => state.businessScope,
    shopType: state => state.shopType,
};

export default new Vuex.Store({
    state,
    actions,
    mutations,
    getters
})
